package com.wlc.base.design.single;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 单例模式
 * @date 2021-09-16 16:42
 */
public class SingleDemo02 {
     /**
      * 懒汉式单例模式
      * */
     private static SingleDemo02 singleDemo;

     private SingleDemo02(){
         System.out.println("私有属性初始化");
     }

     public static SingleDemo02 getInstance(){
         if (singleDemo==null) {
             singleDemo = new SingleDemo02();
             return singleDemo;
         }
         return singleDemo;
     }

    public static void main(String[] args) {
        SingleDemo02 s1 = SingleDemo02.getInstance();
        SingleDemo02 s2 = SingleDemo02.getInstance();
        System.out.println(s1.toString().equals(s2.toString()));
    }
}
